#include <gtest/gtest.h>
#include "ECS/ECS.h"
#include "ECS/Patterns/Nullable.h"
#include "ECS/XML/XmlSerializer.h"
#include "ECS/XML/XmlPaletteLoader.h"
#include "Components.h"

namespace
{

	ECS::XMLSerializer serializer;
	const char* paletteFile = 
"<Objects> \
	<Assembly name=\"test1\"> \
		<ComponentA field1=\"1\" field2 = \"3.5\" />\
	</Assembly>\
</Objects>";
}

TEST(XmlTests, CreateComponentTest)
{
	ECS::Assembly::_metaTable();
	ECS::XMLPaletteLoader::registerClass<ComponentA, ComponentADef>();
	ECS::Palette palette;
	ECS::XMLPaletteLoader::Load(&palette, (uint8_t*)paletteFile);

	auto a = palette.create("test1");
	EXPECT_TRUE(a != nullptr);
	auto ca = a->getComponent<ComponentA>();
	EXPECT_TRUE(ca != nullptr);
	EXPECT_TRUE(ca->field1 == 1);
	EXPECT_TRUE(ca->field2 == 3.5f);
}